package cn.Liujialin.org.service.impl;

import cn.Liujialin.basic.util.PageList;
import cn.Liujialin.org.domain.Department;
import cn.Liujialin.org.mapper.DepartmentMapper;
import cn.Liujialin.org.query.DepartmentQuery;
import cn.Liujialin.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)//委托给事务管理
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    //保存
    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);

    }
    //删除
    @Override
    @Transactional
    public void del(Long id) {
        departmentMapper.del(id);

    }
    //修改
    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);

    }
    //查询单个
    @Override
    public Department findById(Long id) {
        return departmentMapper.findById(id);
    }

    //查询所有
    @Override
    public List<Department> findByAll() {
        return departmentMapper.findByAll();
    }

    //分页以及高级查询
    @Override
    public PageList<Department> queryPage(DepartmentQuery query) {
        Long total= departmentMapper.queryCount(query);
        List<Department> rows = departmentMapper.queryData(query);
        return new PageList<>(total,rows);

    }
    //批量删除
    @Override
    public void patchDelete(List<Long> ids) {
        departmentMapper.patchDelete(ids);
    }

    @Override
    public List<Department> queryTree() {
        return departmentMapper.queryTree();
    }
}
